package com.cccyy.file.merge;

import java.io.*;

public class MergeTxt {
    public static void main(String[] args) throws IOException {
        //将当前目录下的txt文档内容合并
        String fileOutPath = "d:/logs/FileCouontInfo.txt";
        BufferedWriter bw = new BufferedWriter(new FileWriter(fileOutPath));
        File[] files = new File("d:\\data\\merge").listFiles();
        int fileCount = 0;
        int folderCount = 0;
        for (File file : files) {
            if (file.isFile()) {
                fileCount++;
                BufferedReader br = new BufferedReader(new FileReader(file));
                String line;
                while ((line = br.readLine()) != null) {
                    bw.write(line);
                    bw.newLine();
                }
                br.close();
            } else {
                folderCount++;
            }
        }
        bw.close();
        System.out.println("目录下文件个数：" + fileCount);
        System.out.println("目录下文件夹个数：" + folderCount);
    }
}
